﻿using System.ComponentModel;

namespace CoreApi.common
{
    public class Constant
    {
        /// <summary>
        /// 通用返回格式
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public class OutMsg<T>
        {
            public ResponseCode code { get; set; }
            public string msg { get; set; }
            public T data { get; set; }
            public string callback { get; set; }
            public OutMsg()
            {
                code = ResponseCode.Success;
                msg = "ok";
                data = default(T);
            }
            
        }




        /// <summary>
        /// 输出体
        /// </summary>
        public class OutMsg
        {
            public OutMsg()
            {
                code = ResponseCode.Success;
                msg = "success";
                data = "";
            }
            public ResponseCode code { set; get; }
            public string msg { set; get; }
            public string data { set; get; }
        }

        /// <summary>
        /// 上传附件格式
        /// </summary>
        public class SysFiles
        {
            public string name { get; set; }
            public string ext { get; set; }
            public string path { get; set; }
            public double size { get; set; }
        }

        /// <summary>
        /// 枚举返回状态
        /// </summary>
        public enum ResponseCode : int
        {
            /// <summary>
            /// 操作成功
            /// </summary>
            [Description("操作成功")]
            Success = 200,

            /// <summary>
            /// 程序报错
            /// </summary>
            [Description("程序报错")]
            Error = 500,
            /// <summary>
            /// 主动抛错
            /// </summary>
            [Description("主动抛错")]
            customError = 600,
        }



        public class ResponseView
        {
            /// <summary>
            /// 状态码
            /// </summary>
            public int code { get; set; }

            /// <summary>
            /// 返回信息
            /// </summary>
            public string? msg { get; set; }

            /// <summary>
            /// 返回数据
            /// </summary>
            public object? data { get; set; }

            public ResponseView(int Code = 200, string? Message = "success", object? Data = null)
            {
                code = Code;
                msg = Message;
                data = Data;
            }
        }

        /// <summary>
        /// 返回普通数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public class ResponseView<T>
        {
            /// <summary>
            /// 状态码
            /// </summary>
            public int code { get; set; }

            /// <summary>
            /// 返回信息
            /// </summary>
            public string? msg { get; set; }

            /// <summary>
            /// 返回数据
            /// </summary>
            public T? data { get; set; }

            public ResponseView(int Code = 200, string? Message = "success", T? Data = default(T))
            {
                code = Code;
                msg = Message;
                data = Data;
            }
        }

        /// <summary>
        /// 返回分页结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public class PageResultDto<T>
        {
            /// <summary>
            /// 分页数据
            /// </summary>
            public T list { get; set; }

            /// <summary>
            /// 总数
            /// </summary>
            public int total { get; set; }

            /// <summary>
            ///
            /// </summary>
            /// <param name="count"></param>
            /// <param name="items"></param>
            public PageResultDto(int count, T items)
            {
                list = items;
                total = count;
            }
        }






        /// <summary>
        /// 表格列表输出model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public class TableListResponseModel<T>
        {
            public TableListResponseModel()
            {
                total = 0;
                list = default(T);
            }
            public int total { get; set; }
            public T list { get; set; }
        }


        /// <summary>
        /// 表格查询model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public class TableListSearchModel<T>
        {
            /// <summary>
            /// 
            /// </summary>
            public TableListSearchModel()
            {
                pageIndex = 1;
                pageSize = 20;
                order = "";
            }
            /// <summary>
            /// 页码
            /// </summary>
            public int pageIndex { get; set; }
            /// <summary>
            /// 每页条数
            /// </summary>
            public int pageSize { get; set; }
            /// <summary>
            /// 排序，字段名 asc|desc  例：id desc,多个条件用逗号隔开,如，score desc,id asc
            /// </summary>
            public string? order { get; set; }
            /// <summary>
            /// 查询条件
            /// </summary>
            public T where { get; set; }
        }

    }
}
